package logic;


import data.MovieTuple;
import data.SystemData;
import data.UserTuple;
import exceptions.MovieAlreadyExistsException;
//import exceptions.MovieDoesNotExistsException;
import exceptions.UserDoesNotExistsException;
import logic.Logger;

public class AdminHandler {

	public AdminHandler(){

	}



	/**
	 * /**
	 * creates a new movie object, and add it to the hashtable.
	 * if the movie already exists, throws a MovieAlreadyExistsException.
	 * @param name
	 * @param category
	 * @param director
	 * @param lang
	 * @param raters
	 * @param rating
	 * @param year
	 * @param length
	 * @param picture
	 * @return
	 * @throws MovieAlreadyExistsException
	 */
	public boolean addMovie(String name, String category, String director, String lang ,String raters,String rating, String year,  String length, String picture){// throws MovieAlreadyExistsException{

		if (SystemData.getInstance().getMovie(name)!=null){
			return false;
			//throw new MovieAlreadyExistsException();
		}
		else{
			 MovieTuple movieTuple= new MovieTuple(name,category,director,lang,raters,rating,year,length ,picture);
			 SystemData.getInstance().addMovie(movieTuple);//get_movies().put(movieTuple.getKey(),movieTuple);

			 return true;
		}
	}

	/**
	 * deletes a movie from the system.
	 * if the movie does not exists throws MovieDoesNotExistsException.
	 */
	public boolean deleteMovie(String name){// throws MovieDoesNotExistsException{
		MovieTuple movieTuple=null;

		movieTuple= SystemData.getInstance().getMovie(name);
		if (SystemData.getInstance().getMovie(name)==null){
			//throw new MovieDoesNotExistsException();
			return false;
		}
		else{

			 SystemData.getInstance().deleteMovie(movieTuple);

			 ToGuiFacade.getInstance().showDeleteMovieMessage();
			 return true;
		}
	}

	/**
	 * deletes a user from the system.
	 * if the user does not exists throws UserDoesNotExistsException.
	 */
	public UserTuple deleteUser (String userName,String adminName) throws UserDoesNotExistsException{
		//SystemData systemData = SystemData.getInstance();
		UserTuple user = SystemData.getInstance().getUser(userName);
		if (user==null){
			throw new UserDoesNotExistsException();
		}
		else{
			SystemData.getInstance().deleteUser(user);

			Logger log = Logger.getInstance();
			log.userDelete(user, SystemData.getInstance().getUser(adminName));

			ToGuiFacade.getInstance().showDeleteUserMessage();

		}
		return user;


	}


}
